package cn.com.utt.unms.mapper;


import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.com.utt.unms.pojo.SmsRecord;

@Mapper
public interface SmsRecordMapper {

	@Insert("insert into sms_record(marketing_id,msg_id,phone,num,send_time,complete_time,status) values(#{marketingId},#{msgId},#{phone},#{num},#{sendTime},#{completeTime},#{status})")
	void addSmsRecord(SmsRecord msRecord);
	@Select("select * from sms_record where marketing_id=#{marketingId}")
	List<SmsRecord> querySmsRecordByMarketingId(@Param("marketingId") Long marketingId);
	@Update("update sms_record set marketing_id=#{marketingId},msg_id=#{msgId},phone=#{phone},num=#{num},send_time=#{sendTime},complete_time=#{completeTime},status=#{status} where id=#{id}")
    void updateSmsRecord(SmsRecord msRecord);
//	@Delete("delete from sms_record where id=#{id}")
//	void delSmsRecordById(@Param("id") Long id);
	@Select({"<script>",
	    "select id from  sms_record", 
	    "WHERE ", 
	    "marketing_id IN", 
	      "<foreach item='item' index='index' collection='marketingIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	List<Long> querySmsRecordByMarketingIds(@Param("marketingIds") List<Long> marketingIds);
	
	@Delete({"<script>",
	    "delete from sms_record", 
	    "WHERE ", 
	    "id IN", 
	      "<foreach item='item' index='index' collection='ids'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	void delSmsRecordByIds(@Param("ids") List<Long> ids);
	
	@Update("update sms_record set msgId=#{msgId},status=#{status},send_time=#{sendTime} where id=#{id}")
	void updateRecord(SmsRecord smsRecord);
}
